package com.zmn.oms.services.impl.perf;


import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.oms.model.entity.perf.PerfFact;
import com.zmn.oms.model.entity.perf.PerfFactQuery;
import com.zmn.oms.persistence.interfaces.perf.PerfFactDao;
import com.zmn.oms.services.interfaces.perf.PerfFactService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 工单绩效相关-带时间纬度的事实表(PerfFact)表服务实现类
 *
 * @author hankangshuai
 * @since 2019-09-18 15:42:22
 */
@Service("perfFactService")
public class PerfFactServiceImpl implements PerfFactService {
    @Resource
    private PerfFactDao perfFactDao;

    /**
     * 通过主键查询单条数据
     *
     * @param factId 主键
     * @return 实例对象
     */
    @Override
    @ReadOnlyConnection
    public PerfFact findByKey(Integer factId) {
        return this.perfFactDao.findByKey(factId);
    }


    /**
     * 分页条件查询
     *
     * @param perfFactQuery 查询对象
     * @return 对象列表
     */
    @Override
    @ReadOnlyConnection
    public List<PerfFact> listPageByQuery(PerfFactQuery perfFactQuery) {
        return this.perfFactDao.listPageByQuery(perfFactQuery);
    }

    /**
     * 条件查询
     *
     * @param perfFactQuery 查询对象
     * @return 对象列表
     */
    @Override
    @ReadOnlyConnection
    public List<PerfFact> listByQuery(PerfFactQuery perfFactQuery) {
        return this.perfFactDao.listByQuery(perfFactQuery);
    }

    /**
     * 条件计数
     *
     * @param perfFactQuery 查询对象
     * @return 影响行数
     */
    @Override
    @ReadOnlyConnection
    public int countByQuery(PerfFactQuery perfFactQuery) {
        return this.perfFactDao.countByQuery(perfFactQuery);
    }


    /**
     * 通过主键删除数据
     *
     * @param factId 主键
     * @return 影响行数
     */
    @Override
    public int deleteByKey(Integer factId) {
        return this.perfFactDao.deleteByKey(factId);
    }

    /**
     * 批量插入，如果重复则更新
     *
     * @param perfFacts 插入集合
     * @return 影响行数
     */
    @Override
    public Integer insertOnDuplicateUpdateBatch(List<PerfFact> perfFacts) {
        return CollectionUtils.isEmpty(perfFacts) ? 0 : this.perfFactDao.insertOnDuplicateUpdateBatch(perfFacts);
    }
}